package com.scau.ums.service.imp.news;

import com.scau.ums.mapper.CustomedNewsMapper;
import com.scau.ums.mapper.NewsMapper;
import com.scau.ums.model.News;
import com.scau.ums.service.diyListNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class diyNewsImp implements diyListNewsService {

    @Autowired
    private NewsMapper newsMapper;

    @Autowired
    private CustomedNewsMapper customedNewsMapper;
    //获取某一页的所有新闻
    @Override
    public List<News> getNewsCurPageRecords(int curPage){
        int start = (curPage - 1) * pageSize;//当前开始记录下标
        return customedNewsMapper.selectRowByPageSetOrderByClause
                ("news","date DESC",start,pageSize,"1=1");
    }
    //获取新闻总页数
    @Override
    public int getNewsPageSum(){
        int totalSum=customedNewsMapper.getNewsSum();
        double tmp = (double)totalSum/pageSize;
        int pageSum = (int) Math.ceil(tmp);//总页数
        return pageSum;
    }
}
